<template>
  <section class="rela_search" @click="closeContextmenu">
    <!--<nav-index @cliclSearchImg="cliclSearchImg"></nav-index>-->
    <!--<article class="art_shaixuan">-->
    <!--<el-form :inline="true" :model="form" class="demo-form-inline">-->
    <!--<el-form-item label="筛选">-->
    <!--<el-radio-group v-model="form.shaixuan">
					      <el-radio label="1">全部</el-radio>
					      <el-radio label="2">人物关系</el-radio>
					      <el-radio label="3">空间对象</el-radio>
					      <el-radio label="4">社会对象</el-radio>
					      <el-radio label="5">地域关系</el-radio>
					      <el-radio label="6">业缘关系</el-radio>
					      <el-radio label="7">人案关系</el-radio>
					      <el-radio label="8">亲缘关系</el-radio>
					       <el-radio label="9">标识关系</el-radio>
    </el-radio-group>-->
    <!--<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
					 	<el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
						    <el-checkbox v-for="(city,index) in cities" :label="index" :key="city">{{city}}</el-checkbox>
    </el-checkbox-group>-->
    <!--</el-form-item>-->
    <!--</el-form>-->
    <!--</article>-->
    <div class="echart_index">
      <echarts-base
        @contextmenu="contextmenu"
        @clickEcharts="clickEcharts"
        :resize="index_resize"
        v-if="echarts_index"
        :idName="idName"
        :option="option2"
      ></echarts-base>
    </div>
    <el-dialog
      class="diy_dialog1"
      :title="dialogUserTitle"
      width="1240px"
      :visible.sync="dialogTableVisible"
      v-if="dialogTableVisible"
    >
      <dialog-analyse :analyse="analyse"></dialog-analyse>
    </el-dialog>
    <el-dialog
      class
      :title="dialogUserTitle"
      width="800px"
      :visible.sync="dialogTableVisible_biaozhihao"
      v-if="dialogTableVisible_biaozhihao"
    >
      <dialog-user-biaozhihao style="height: 500px;" :dialogUserInfo="dialogUserInfo"></dialog-user-biaozhihao>
    </el-dialog>
    <div class="contextmenu-div" id="contextmenuDiv" v-show="contextmenu_div">
      <ul>
        <li @click="showInfo">查看基本信息</li>
        <li @click="superFile()">查看详细信息</li>
      </ul>
    </div>

    <div class="person_info_div">
      <div
        :id="'idNum_'+item.sfzh"
        class="person_info_div_item"
        v-for="(item,index) in personInfo"
        :key="index"
      >
        <img class="close_png" src="../assets/imgs/tupu09.png" @click="closeInfo(index)">
        <p style="text-align: center;background: #fff;">
          <img @error="pic($event)" :src="item.img_url">
        </p>
        <p>姓名：{{item.xm}}</p>
        <p>性别 : {{item.xb}}&nbsp;&nbsp;&nbsp;&nbsp;婚姻 : {{item.hyzk}}&nbsp;&nbsp;&nbsp;&nbsp;年龄 : {{item.csrq}}</p>
        <p>文化程度：{{item.whcd}}</p>
        <p>身份证号：{{item.gmsfhm}}</p>
        <p>户口所在地 : {{item.hkszd}}</p>
        <p>住址详址 : {{item.xz}}</p>
        <!-- <p>住址详址 : {{item.zzxz}}</p> -->
        <!--<p class="super" @click="superFile(item.sfzh)">跳到到超级档案</p>-->
      </div>
    </div>
  </section>
</template>

<script>
const cityOptions = [
  "人物关系",
  "空间对象",
  "社会对象",
  "地域关系",
  "业缘关系",
  "人案关系",
  "亲缘关系",
  "标识关系"
];
import echartsBase from "@/components/echars_base";
import { option2 } from "@/components/common";
import dialogAnalyse from "@/components/dialogAnalyse";
import {
  gotoSuperFile,
  apiGetInfo,
  apiClickGetInfo,
  apiGetConfig,
  apiShowInfo,
  apiClickEdge2,
  apiShowRelation,
  apiShowDialog
} from "@/components/api";
import dialogUserBiaozhihao from "@/components/dialogUserBiaozhihao";
import moren_pic from "@/assets/imgs/user.png";
import star from "@/assets/imgs/tupu73.png";
export default {
  components: {
    echartsBase,
    dialogAnalyse,
    dialogUserBiaozhihao
  },
  props: {
    searchInput: {
      type: String,
      default: ""
    },
    search_change: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      type: "search",
      personInfo: [],
      /*多选*/
      checkAll: false,
      checkedCities: ["上海", "北京"],
      cities: cityOptions,
      isIndeterminate: true,
      /*多选*/
      index_resize: { height: 800, width: 800 },
      menu_item: {},
      isShowInfo: false,
      echarts_index: true,
      dialogUserInfo: {},
      dialogTableVisible: false,
      dialogTableVisible_biaozhihao: false,
      contextmenu_div: false,
      dialogUserTitle: "",
      idName: "echarts_index",
      moren_pic: moren_pic /*默认图片*/,
      times: "",
      star: star,
      form: {
        shaixuan: "1",
        input1: ""
      },
      option: {},
      option2: option2,
      analyse: {
        firstTable: {
          firstName: "",
          firstSFZ: "",
          gxzs: 0,
          secName: "",
          secSFZ: ""
        },
        tableData1: [],
        tableLable1: {
          rele_type: "关系分数",
          rele_num: "次数",
          rele_name: "关系名称"
        },
        table3: [
          {
            name: "",
            myself: "",
            tableData3: [],
            tableLable3: {}
          }
        ]
      }
    };
  },
  methods: {
    superFile() {
      //      			console.log(this.menu_item);
      if (this.menu_item.data.zjhm == 0) {
        return;
      }
      gotoSuperFile(this, this.menu_item.data.zjhm.trim());
    },
    pic(ev) {
      //      			console.log(ev);
      ev.target.src = moren_pic;
    },
    dropActive(event) {
      ev.preventDefault();
    },
    clickEcharts(val) {
      /*左键*/
      //      			console.log(val);
      if (val.dataType != "edge") {
        return;
      }
      if (!val.data.hasOwnProperty("code")) {
        return;
      }
      if (val.data.code == 0) {
        return;
      } /*没有这俩个条件，查不到的*/
      this.dialogTableVisible = true;
      apiClickEdge2(this, val);
    },
    contextmenu(val) {
      /*右键*/
      //      			if(val.dataIndex<=29&&val.dataIndex!=0){
      //      				return
      //      			}
      let div_diy = document.getElementById("contextmenuDiv");
      //      			console.log(div_diy)
      //      			console.log(val)
      div_diy.style.top = val.event.event.clientY + "px";
      div_diy.style.left = val.event.event.clientX + "px";
      this.menu_item = val;
      if (this.menu_item.dataType == "edge" || this.menu_item.data.zjhm == 0) {
        return;
      } /*标志号的没有身份证这个字段*/
      this.contextmenu_div = true;
    },
    closeContextmenu() {
      /*关闭菜单*/
      this.contextmenu_div = false;
    },
    handleCheckAllChange(val) {
      /*处理变化，多选的*/
      this.checkedCities = val ? cityOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      /*处理变化，多选的*/
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
    cliclSearchImg(val) {
      /*点击搜索人*/
      if (val.trim() == "") {
        return;
      }
      this.seachPerson(val.trim());
    },
    seachPerson(val) {
      /*搜索人*/
      this.echarts_index = false;
      apiGetInfo(this, val);
    },
    showInfo() {
      /*查看信息*/
      //			    	console.log(this.menu_item);
      if (this.menu_item.data.zjhm == 0) {
        return;
      }
      if (
        this.menu_item.data.hasOwnProperty("touchId") ||
        this.menu_item.data.hasOwnProperty("fatherName")
      ) {
        apiShowDialog(this, this.menu_item.data.touchId); /*标志号的查看详情*/
      } else {
        apiShowInfo(this, this.menu_item); /*查找关系的查看详情*/
      }
    },
    showRelation() {
      /*查看关系*/
      if (this.menu_item.dataIndex == 0) {
        return;
      }
      apiShowRelation(this, this.menu_item);
    },
    closeInfo(index) {
      this.personInfo.splice(index, 1);
    },
    dragFunc(id, index) {
      /*拖拽*/
      //			    	id = 'info_div';
      //			    	console.log(id)
      var Drag = document.getElementById(String(id));
      //				    console.log(Drag)
      Drag.onmousedown = function(event) {
        //				    	console.log('dwadw');
        var ev = event || window.event;
        event.stopPropagation();
        var disX =
          ev.clientX - Drag.offsetLeft + 210 * index; /*解决偏移位置问题*/
        var disY = ev.clientY - Drag.offsetTop;
        document.onmousemove = function(event) {
          var ev = event || window.event;
          Drag.style.left = ev.clientX - disX + "px";
          Drag.style.top = ev.clientY - disY + "px";
          Drag.style.cursor = "move";
        };
      };
      Drag.onmouseup = function() {
        document.onmousemove = null;
        this.style.cursor = "default";
      };
    },
    finish(i = 0) {
      /*递归去解决异步问题，我发现我很喜欢用递归*/
      //					console.log('要优化')
      if (i == this.option2.series[0].data.length) {
        this.echarts_index = true;
        console.log("已运行完毕,请等待引擎渲染画面");
        return;
      }
      var ImgObj = new Image();
      ImgObj.setAttribute("crossOrigin", "anonymous");
      ImgObj.addEventListener("load", () => {
        if (!this.option2.series[0].data[i].hasOwnProperty("hasCheck")) {
          this.radius = ImgObj.naturalWidth / 2;
          ImgObj.crossOrigin = "";
          this.diameter = this.radius * 2;
          this.canvas.width = this.diameter;
          this.canvas.height = this.diameter;
          this.contex.clearRect(0, 0, this.diameter, this.diameter);
          this.contex.save();
          this.contex.beginPath();
          this.contex.arc(
            this.radius,
            this.radius,
            this.radius,
            0,
            2 * Math.PI
          ); //画出圆
          this.contex.clip(); //裁剪上面的圆形
          //						             console.log(ImgObj)
          this.contex.drawImage(
            ImgObj,
            0,
            0,
            this.diameter,
            this.diameter,
            0,
            0,
            this.diameter,
            this.diameter
          ); // 在刚刚裁剪的园上画图
          if (
            this.option2.series[0].data[i].hasOwnProperty("flag") &&
            this.option2.series[0].data[i].flag != 0 &&
            this.option2.series[0].data[i].flag.hasOwnProperty("code") &&
            this.option2.series[0].data[i].flag.code != "0"
          ) {
            this.contex.drawImage(
              this.ImgObj2,
              0,
              0,
              this.diameter,
              this.diameter,
              this.radius * 1.2,
              this.radius * 0.2,
              this.diameter * 2,
              this.diameter * 2
            ); // 在刚刚裁剪的园上画星
            //									 	console.log(this.option2.series[0].data[i])
          }
          this.contex.restore(); // 还原状态
          this.option2.series[0].data[i].symbol =
            "image://" + this.canvas.toDataURL("image/png", 1);
          this.option2.series[0].data[i].hasCheck = true;
        }
      });
      ImgObj.addEventListener("error", () => {
        this.option2.series[0].data[i].symbol = "image://" + this.moren_pic;
        if (
          this.option2.series[0].data[i].hasOwnProperty("flag") &&
          this.option2.series[0].data[i].flag != 0 &&
          this.option2.series[0].data[i].flag.hasOwnProperty("code") &&
          this.option2.series[0].data[i].flag.code != "0"
        ) {
          //									console.log(this.option2.series[0].data[i])
          let ImgObj_err = new Image();
          ImgObj_err.setAttribute("crossOrigin", "anonymous");
          ImgObj_err.src = this.moren_pic;
          this.radius = ImgObj_err.naturalWidth / 2;
          ImgObj_err.crossOrigin = "";
          this.diameter = this.radius * 2;
          this.canvas.width = this.diameter;
          this.canvas.height = this.diameter;
          this.contex.clearRect(0, 0, this.diameter, this.diameter);
          this.contex.save();
          this.contex.beginPath();
          this.contex.arc(
            this.radius,
            this.radius,
            this.radius,
            0,
            2 * Math.PI
          ); //画出圆
          this.contex.clip(); //裁剪上面的圆形
          this.contex.drawImage(
            ImgObj_err,
            0,
            0,
            this.diameter,
            this.diameter,
            0,
            0,
            this.diameter,
            this.diameter
          ); // 在刚刚裁剪的园上画图
          this.contex.drawImage(
            this.ImgObj2,
            0,
            0,
            this.diameter,
            this.diameter,
            this.radius * 1.2,
            this.radius * 0.2,
            this.diameter,
            this.diameter
          ); // 在刚刚裁剪的园上画星
          this.option2.series[0].data[i].symbol =
            "image://" + this.canvas.toDataURL("image/png", 1);
        }
      });
      ImgObj.src = this.option2.series[0].data[i].userImg.substring(
        8,
        this.option2.series[0].data[i].symbol.length
      );

      this.finish(i + 1);
    },
    emitRes(res) {
      this.$emit("emitRes", res);
    },
    resetCanvas() {
      this.canvas = document.createElement("canvas");
      this.contex = this.canvas.getContext("2d");
      this.ImgObj = new Image();
      this.ImgObj2 = new Image();
      this.ImgObj2.src = this.star;
    }
  },
  created() {
    this.index_resize.height = window.innerHeight;
    this.index_resize.width = window.innerWidth;
    this.option = JSON.parse(JSON.stringify(this.option2));
    //      	console.log("获取配置开始")
    //      	apiGetConfig();/*获取配置*/
    this.resetCanvas(); /*初始化cancas对象*/
  },
  watch: {
    search_change(newVal, oldVal) {
      /*搜索人有变化*/
      this.cliclSearchImg(this.searchInput);
    }
  }
};
</script>

<style>
.rela_search {
  height: 100%;
}

.rela_search article.art_shaixuan {
  height: 50px;
  /* line-height: 50px; */
  background: #f8f8f8;
  text-align: center;
  padding-top: 10px;
  font-size: 14px;
}
.rela_search .echart_index {
  margin: auto;
  height: calc(100% - 60px);
}
.rela_search .contextmenu-div {
  position: absolute;
  min-width: 100px;
  background: #fff;
  z-index: 3000;
  top: 0;
  left: 0;
  border-radius: 4px;
  overflow: hidden;
  border: solid 1px #bbb6b6;
}
.rela_search .contextmenu-div ul {
  border-radius: 4px;
  overflow: hidden;
}
.rela_search .contextmenu-div li:hover {
  background: #bdbdbd;
  color: #fff;
}
.rela_search .contextmenu-div li {
  /*float: left;*/
  cursor: pointer;
  list-style: none;
  padding: 6px 20px;
  color: #1145de;
  font-size: 13px;
}
.rela_search .el-checkbox-group {
  float: right;
}

.rela_search .el-checkbox {
  margin-right: 20px;
}
.rela_search input.title_input {
  background: #fff0;
  border: solid 1px #fff;
  border-radius: 40px;
  width: 240px;
  height: 25px;
  color: #fff;
  padding-left: 15px;
}
.rela_search .nav_title_input {
  margin-left: 40px;
  position: relative;
}
.rela_search .search_input_img {
  position: absolute;
  top: 3px;
  right: 10px;
  width: 18px;
  cursor: pointer;
}
.rela_search .person_info_div {
  position: absolute;
  top: 130px;
  left: 120px;
  z-index: 11;
  height: 286px;
  max-width: 80%;
}
.rela_search .person_info_div_item {
  width: 210px;
  background: #f5f5f5;
  z-index: 3000;
  display: inline-block;
  position: relative;
  vertical-align: top;
  cursor: move !important;
}
.rela_search .person_info_div_item p {
  margin: 10px;
  font-size: 12px;
}
.rela_search .person_info_div_item p.super {
  cursor: pointer;
}

.rela_search .person_info_div_item p img {
  width: 50%;
  text-align: center;
}

.rela_search .close_png {
  width: 20px;
  cursor: pointer;
  position: absolute;
  right: 0;
  top: 1px;
}
</style>